﻿using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
public partial class Admin_UserPayEdit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            anolb.Text = Request.QueryString["ano"].ToString();
            namelb.Text = Request.QueryString["name"].ToString();
            if (Request.QueryString["pid"] == null || Request.QueryString["pid"].ToString() == "")
            {
                Tools.OpenWindow(this, "当前页面操作异常！请按正常操作执行");
                return;
            }

            DataTable dt = new PublicSqlService().GetData("*", "Tb_Pay", "ID=" + Request.QueryString["pid"].ToString());

            if (dt.Rows.Count != 1)
            {
                Tools.OpenWindow(this, "数据异常！");
                return;
            }



            payall.Value = dt.Rows[0]["PayAll"].ToString();

            selectpaytype.Value = dt.Rows[0]["PayType"].ToString();

            payabout.Value = dt.Rows[0]["ReMark"].ToString();

            paydate.Value = dt.Rows[0]["PayDate"].ToString();


        }

    }

    protected void payok_Click(object sender, ImageClickEventArgs e)
    {
        if (payall.Value.Trim() == "")
        {
            Tools.OpenWindow(this, "请输入支付总额");
            return;
        }
        Tools t = new Tools();
        Hashtable hs = new Hashtable();

        PublicSqlService ps = new PublicSqlService();


        hs.Add("PayAll", t.StringToDecimalDif(payall.Value.Trim()));
        hs.Add("PayType", selectpaytype.Value);
        hs.Add("ReMark", payabout.Value);
        hs.Add("PayDate", t.StringToTime(paydate.Value));



        if (ps.Update(hs, "Tb_Pay", "ID=" + Request.QueryString["pid"].ToString()))
        {


            Hashtable hs2 = new Hashtable();
            hs2.Clear();
            hs2.Add("admin", Session["UserName"].ToString());
            hs2.Add("Url", Session["url"]);
            hs2.Add("date", DateTime.Now);
            hs2.Add("trackingno", "");
            hs2.Add("type", "paid money");
            hs2.Add("account", Request.QueryString["ano"]);
            hs2.Add("amount", t.StringToDecimalDif(payall.Value.Trim()));
            new PublicSqlService().Insert(hs2, "log");


            Tools.OpenWindow(this, "保存成功", Request.Url.ToString());
        }
        else
        {
            Tools.OpenWindow(this, "保存失败！");
        }
    }
}
